<template>
	<view class="jnpf-wrap jnpf-wrap-workflow">
		<u-form :model="dataForm" ref="dataForm" :errorType="['toast']" label-position="left" label-width="150"
			label-align="left">
			<u-form-item v-if="judgeShow('tc001')" label="单别">
				<u-input v-model="infoObj.tc001" placeholder="请输入请购单别" disabled></u-input>
			</u-form-item>
			<u-form-item v-if="judgeShow('tc002')" label="单号">
				<u-input v-model="infoObj.tc002" placeholder="请输入单号" disabled></u-input>
			</u-form-item>
			<u-form-item v-if="judgeShow('tc003')" label="日期">
				<u-input v-model="infoObj.tc003" placeholder="请输入日期" disabled></u-input>
			</u-form-item>
			<u-form-item v-if="judgeShow('tc011')" label="采购人员">
				<u-input v-model="listInfo.optionTwo" placeholder="请输入采购人员" disabled></u-input>
			</u-form-item>
			<u-form-item v-if="judgeShow('tc004')" label="供应商">
				<u-input v-model="listInfo.optionFour" placeholder="请输入供应商" disabled></u-input>
			</u-form-item>
			<u-form-item v-if="judgeShow('tc004')" label="供应商名称">
				<u-input v-model="listInfo.optionThree" placeholder="请输入供应商名称" disabled></u-input>
			</u-form-item>
			<u-form-item v-if="judgeShow('tc005')" label="交易币种">
				<u-input v-model="infoObj.tc005" placeholder="请输入交易币种" disabled></u-input>
			</u-form-item>
			<u-form-item v-if="judgeShow('tc027')" label="付款条件">
				<u-input v-model="listInfo.JoinStr" placeholder="请输入付款条件" disabled></u-input>
			</u-form-item>
			<u-form-item v-if="judgeShow('tc018')" label="税种">
				<u-input v-model="categoriesOfTaxesName" placeholder="请输入税种" disabled></u-input>
			</u-form-item>
			<u-form-item v-if="judgeShow('tc010')" label="工厂">
				<u-input v-model="listInfo.gochang" placeholder="请输入工厂" disabled></u-input>
			</u-form-item>
			<u-form-item v-if="judgeShow('tc004')" label="联系人">
				<u-input v-model="listInfo.name" placeholder="请输入联系人" disabled></u-input>
			</u-form-item>

			<u-form-item v-if="judgeShow('tc009')" label="备注" prop="fileJson">
				<u-input v-model="infoObj.tc009" type="textarea" placeholder="备注" disabled></u-input>
			</u-form-item>

			<view class="jnpf-table" style="margin-top: 24rpx;">
				<view class="jnpf-table-item" style="margin-bottom: 24rpx;" v-for="(item,i) in lst" :key="i">
					<u-form-item label="序号">
						{{i+1}}
					</u-form-item>
					<u-form-item v-if="judgeShow('td004')" label="品号">
						<u-input v-model="item.td004" placeholder="品号" disabled></u-input>
					</u-form-item>
					<u-form-item v-if="judgeShow('td005')" label="品名">
						<u-input v-model="item.td005" placeholder="品名" disabled></u-input>
					</u-form-item>
					<u-form-item v-if="judgeShow('td006')" label="规格">
						<u-input v-model="item.td006" placeholder="规格" disabled></u-input>
					</u-form-item>
					<u-form-item v-if="judgeShow('td009')" label="单位">
						<u-input v-model="item.td009" placeholder="单位" disabled></u-input>
					</u-form-item>
					<u-form-item v-if="judgeShow('td008')" label="数量">
						<u-input v-model="item.td008" placeholder="数量" disabled></u-input>
					</u-form-item>
					<u-form-item v-if="judgeShow('td010')" label="单价">
						<u-input v-model="item.td010" placeholder="单价" disabled></u-input>
					</u-form-item>
					<u-form-item label="参考核价(含税)">
						<u-input v-model="item.referPrice" placeholder="参考核价(含税)" disabled></u-input>
					</u-form-item>
					<u-form-item label="参考成本(含税)">
						<u-input v-model="item.ReferenceCost" placeholder="参考成本(含税)" disabled></u-input>
					</u-form-item>
					<u-form-item v-if="judgeShow('td011')" label="金额">
						<u-input v-model="item.td011" placeholder="金额" disabled></u-input>
					</u-form-item>
					<u-form-item v-if="judgeShow('td026')" label="请购单别">
						<u-input v-model="item.td026" placeholder="请购单别" disabled></u-input>
					</u-form-item>
					<u-form-item v-if="judgeShow('td027')" label="请购单号">
						<u-input v-model="item.td027" placeholder="请购单号" disabled></u-input>
					</u-form-item>
					<u-form-item v-if="judgeShow('td028')" label="请购序号">
						<u-input v-model="item.td028" placeholder="请购序号" disabled></u-input>
					</u-form-item>
					<u-form-item v-if="judgeShow('td012')" label="预计交货日">
						<u-input v-model="item.td012" placeholder="预计交货日" disabled></u-input>
					</u-form-item>

					<u-form-item v-if="judgeShow('td007')" label="交货仓库">
						<u-input v-model="item.td007" placeholder="交货仓库" disabled></u-input>
					</u-form-item>
					<u-form-item v-if="judgeShow('td007')" label="仓库名称">
						<u-input v-model="td007Name" placeholder="仓库名称" disabled></u-input>
					</u-form-item>
					<u-form-item v-if="judgeShow('tc009')" label="备注">
						<u-input v-model="item.tc009" type="textarea" placeholder="备注" disabled></u-input>
					</u-form-item>
				</view>
			</view>

			<view class="jnpf-table" style="margin-top: 24rpx;">
				<u-form-item v-if="judgeShow('tc019')" label="采购金额">
					<u-input v-model="infoObj.tc019" placeholder="采购金额" disabled></u-input>
				</u-form-item>
			</view>
			<view class="jnpf-table" style="margin-top: 24rpx;">
				<u-form-item v-if="judgeShow('tc020')" label="税额">
					<u-input v-model="infoObj.tc020" placeholder="税额" disabled></u-input>
				</u-form-item>
			</view>

			<view class="jnpf-table" style="margin-top: 24rpx;">
				<u-form-item label="价税合计">
					{{accAdd(infoObj.tc019,infoObj.tc020)}}
				</u-form-item>
			</view>

		</u-form>
	</view>
</template>

<script>
	import comMixin from '../mixin'
	import {
		getGoodsList,
		getCustomerList,
		Info,
		Create,
		Update,
	} from '@/api/apply/order'
	import {
		getInfo
	} from '@/api/workFlow/flowBefore'
	import {
		getDictionaryDataSelector,
		getDataInterfaceDataInfo
	} from '@/api/common'
	export default {
		mixins: [comMixin],
		data() {
			return {
				categoriesOfTaxesName: '',
				categoriesOfTaxesLst: [],

				tel: '', //联系人
				telTwo: '', //联系人

				hide: false,
				billEnCode: 'OrderNumber',
				dataForm: {

				},
				infoObj: {

				},
				lst: [],


				info: {},
				formConf: {},
				listInfo: {
					optionOne: '',
					optionTwo: '',
					optionThree: '',
					optionFour: '',
					JoinStr: '',
					gochang: '',
					name: '',
				},
				td007Name: '',
			}
		},


		methods: {
			init(data, id, flowFormContentJson) {
				this.info = data
				this.id = id
				this.dataForm = data
				this.setting = data
				this.lst = data.purtbList
				this.getInfoFn(flowFormContentJson)
			},
			getInfoFn(data) {
				getInfo({
					tc001: data.tc001,
					tc002: data.tc002,
				}).then(res => {
					if (res.code == 200) {
						this.lst = res.data.purtdList
						this.infoObj = res.data
						let tc011 = res.data.tc011 //查询采购人员参数
						let tc004 = res.data.tc004 //查询采购公司名称参数
						let tc027 = res.data.tc027 //查询交易
						let tc010 = res.data.tc010 //查询工厂
						if (this.lst.length > 0) {
							this.getDataInterfaceDataInfoTcName(this.lst[0].td007)
						}
						this.getDictionaryDataSelectorFn()
						this.getDataInterfaceDataInfoMV002(tc011)
						this.getDataInterfaceDataInfoMA003(tc004)
						this.getDataInterfaceDataInfoJoinStr(tc027)
						this.getDataInterfaceDataInfoGoChang(tc010)
					}
				})
			},
			/**
			 * 查询税种列表
			 */
			getDictionaryDataSelectorFn() {
				getDictionaryDataSelector('411695330707391429').then(res => {
					if (res.code == 200) {
						this.categoriesOfTaxesLst = res.data.list
						this.categoriesOfTaxesLst.forEach(res => {

							if (res.enCode == this.infoObj.tc018) {
								this.categoriesOfTaxesName = res.fullName

							}
						})
					}
				})
			},
			getDataInterfaceDataInfoTcName(id) {
				let data = {
					id,
					interfaceId: '362114335423601221',
					propsValue: 'MC001',
					dblink: '',
					relationField: 'MC001',
				}
				getDataInterfaceDataInfo('362114335423601221', data).then(res => {

					if (res.code == 200) {
						this.td007Name = res.data.MC002
					}
				})
			},
			getDataInterfaceDataInfoMV002(id) {

				let data = {
					id,
					interfaceId: '445425382452126213',
					propsValue: 'MV001',
					dblink: this.id,
					relationField: 'JoinStr',
				}

				getDataInterfaceDataInfo('445425382452126213', data).then(res => {

					if (res.code == 200) {
						this.listInfo.optionTwo = res.data.JoinStr
					}
				})
			},
			getDataInterfaceDataInfoMA003(id) {
				let data = {
					id,
					interfaceId: 381247065990113925,
					propsValue: 'MA001',
					dblink: this.id,
					relationField: 'MA001',
				}
				getDataInterfaceDataInfo('381247065990113925', data).then(res => {
					if (res.code == 200) {

						this.listInfo.optionThree = res.data.MA003
						this.listInfo.optionFour = res.data.MA001
						this.listInfo.name = res.data.MA013
					}
				})
			},
			getDataInterfaceDataInfoGoChang(id) {
				let data = {
					id,
					interfaceId: 362111000289221189,
					propsValue: 'MB001',
					relationField: 'JoinStr',
				}
				getDataInterfaceDataInfo('362111000289221189', data).then(res => {
					if (res.code == 200) {
						this.listInfo.gochang = res.data.JoinStr

					}
				})
			},
			getDataInterfaceDataInfoJoinStr(id) {
				let data = {
					id,
					interfaceId: 362115953258928709,
					propsValue: 'NA002',
					relationField: 'JoinStr',
				}
				getDataInterfaceDataInfo('362115953258928709', data).then(res => {
					if (res.code == 200) {
						this.listInfo.JoinStr = res.data.JoinStr
					}
				})
			},
			selfGetInfo() {
				Info(this.setting.id).then(res => {
					this.dataForm = res.data
					if (this.dataForm.fileJson) {
						this.fileList = JSON.parse(this.dataForm.fileJson)
					}
				})
			},
			selfSubmit() {
				this.dataForm.status = this.eventType === 'submit' ? 0 : 1
				if (this.eventType === 'save') return this.selfHandleRequest()
				uni.showModal({
					title: '提示',
					content: '您确定要提交当前流程吗？',
					success: res => {
						if (res.confirm) {
							this.selfHandleRequest()
						}
					}
				})
			},
			selfHandleRequest() {
				if (!this.dataForm.id) delete(this.dataForm.id)
				const formMethod = this.dataForm.id ? Update : Create
				formMethod(this.dataForm).then(res => {
					uni.showToast({
						title: res.msg,
						complete: () => {
							setTimeout(() => {
								uni.$emit('refresh')
								uni.navigateBack()
							}, 1500)
						}
					})
				})
			},
			initData() {
				getGoodsList().then(res => {
					this.goodsOptions = res.data.list
				})
				getCustomerList().then(res => {
					this.customerOptions = res.data.list
				})
			},
			selfInit() {
				this.addGoods()
				this.addPlan()
			},
			onChange(e) {
				const user = e[0]
				this.dataForm.salesmanName = user.fullName
			},
			addGoods() {
				const item = {
					goodsId: '',
					goodsCode: '',
					goodsName: '',
					specifications: '',
					unit: '',
					qty: '',
					price: '',
					amount: '',
					discount: null,
					cess: null,
					actualPrice: '',
					actualAmount: '',
					description: ''
				}
				this.dataForm.goodsList.push(item)
			},
			delGoods(index) {
				this.dataForm.goodsList.splice(index, 1)
			},
			addPlan() {
				const item = {
					receivableDate: '',
					receivableRate: '',
					receivableMoney: '',
					receivableMode: '',
					abstract: ''
				}
				this.dataForm.collectionPlanList.push(item)
			},
			delPlan(index) {
				this.dataForm.collectionPlanList.splice(index, 1)
			},
			onGoodsChange(e, i) {
				const goods = e[0]
				this.dataForm.goodsList[i] = {
					goodsId: goods.id,
					goodsCode: goods.code,
					goodsName: goods.text,
					specifications: goods.specifications,
					unit: goods.unit,
					qty: 1,
					price: goods.price,
					amount: goods.price,
					discount: 100,
					cess: 0,
					actualPrice: goods.price,
					actualAmount: goods.price,
					description: ''
				}
				this.$forceUpdate()
			},
			onCustomerChange(e) {
				const customer = e[0]
				this.dataForm.customerName = customer.text
			},
			count(row) {
				//金额 = 数量*单价
				row.amount = this.jnpf.toDecimal(parseFloat(row.price) * parseFloat(row.qty))
				//折扣价 = (单价*折扣)
				var discountPrice = row.price * (row.discount / 100);
				//实际单价 = 折扣价 * (1 + (税率 / 100))
				row.actualPrice = this.jnpf.toDecimal(discountPrice * (1 + (row.cess / 100)));
				//实际金额
				row.actualAmount = this.jnpf.toDecimal(parseFloat(row.actualPrice) * parseFloat(row
					.qty))
				this.$forceUpdate()
			}
		}
	}
</script>